package com.itheima.dao.impl;

import com.itheima.dao.TeacherDao;
import com.itheima.domain.Teacher;

import java.util.ArrayList;

public class TeacherDaoImpl implements TeacherDao {
    ArrayList<Teacher> allTeachers = new ArrayList<>();

    {
        allTeachers.add(new Teacher("itheima000", "admin", "22", "1999-09-09"));
        allTeachers.add(new Teacher("itheima001", "root", "22", "1999-09-09"));
    }

    @Override
    public void addTeacher(Teacher teacher) {
        allTeachers.add(teacher);
    }

    @Override
    public void delectTeacher(int index) {
        allTeachers.remove(index);
    }

    @Override
    public void updateTeacher(int index, Teacher teacher) {
        allTeachers.set(index,teacher);
    }

    @Override
    public ArrayList<Teacher> findAllTeacher() {
        return allTeachers;
    }

    @Override
    public int findTeacherById(String id) {
        for (int i = 0; i < allTeachers.size(); i++) {
            if (allTeachers.get(i).getId().equals(id)){
                return i;
            }
        }
        return -1;
    }
}

